package dao;

import hibernate.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import dto.DestinoDTO;
import entities.CargaEntity;
import entities.DestinoEntity;

public class DestinoDAO {
	private static DestinoDAO instancia = null;
	private static SessionFactory sf = null;
	
	private DestinoDAO(){}
	
	public static DestinoDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new DestinoDAO();
		} 
		return instancia;
	}
	
	public void grabarDestino(DestinoDTO destino){
		Session session = sf.openSession();
		session.beginTransaction();
		session.persist(destino);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}
	
	public void actualizarDestino(DestinoDTO destino){
		Session session = sf.openSession();
		session.beginTransaction();
		session.saveOrUpdate(destino);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}
	
	public DestinoEntity LoadDestino(String dire) 
	{
		Session session = sf.openSession();
		session.beginTransaction();
		DestinoEntity ent = (DestinoEntity) session.get(DestinoEntity.class, dire);
		session.flush();
		session.getTransaction().commit();
		session.close();
		return ent;
	}
}

